package huawei.js2025;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * 密室逃生游戏
 */
public class Question11 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String key = sc.nextLine(); // 钥匙
        String[] boos = sc.nextLine().trim().split(" ");

        Map<Character, Integer> keyMap = new HashMap<>();
        char[] charArray = key.toCharArray();
        for (int i = 0; i < charArray.length; i++) {
            keyMap.put(charArray[i], keyMap.getOrDefault(charArray[i], 0) + 1);
        }

        for (int i = 0; i < boos.length; i++) {
            String box = boos[i];
            Map<Character, Integer> map = new HashMap<>();
            for (int j = 0; j < box.length(); j++) {
                char ch = box.charAt(j);
                if (ch >= 'a' && ch <= 'z') {
                    map.put(ch, map.getOrDefault(ch, 0) + 1);
                } else if (ch >= 'A' && ch <= 'Z') {
                    ch += 32;
                    map.put(ch, map.getOrDefault(ch, 0) + 1);
                }
            }

            if (keyMap.keySet().containsAll(map.keySet()) && map.keySet().containsAll(keyMap.keySet())) {
                boolean flag = true;
                for (Character k : map.keySet()) {
                    if (map.get(k) != keyMap.get(k)) {
                       flag = false;
                        break;
                    }
                }
                if (flag) {
                    System.out.println(i + 1);
                }
            }
        }

    }
}
